<?php

namespace App\Admin\Actions\Tree;

use App\Models\Content\ArticleCategory;
use Dcat\Admin\Tree\RowAction;
use Dcat\Admin\Traits\HasPermissions;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;

class ArticleCategoryShow extends RowAction
{
    public function handle()
    {
        $key = $this->getKey();

        $category = ArticleCategory::find($key);

        $category->update(['display' => $category->display ? 0 : 1]);

        return $this
            ->response()
            ->success(trans('admin.update_succeeded'))
            ->location('article-category');
    }

    public function title()
    {
        $icon = $this->getRow()->display ? 'icon-eye-off' : 'icon-eye';

        return "&nbsp;<i class='feather $icon'></i>&nbsp;";
    }

    /**
	 * @return string|array|void
	 */
	public function confirm()
	{
		 return ['Confirm?', sprintf('确定要 %s 文章分类吗?',$this->getRow()->display ? "隐藏" :"显示")];
	}

    /**
     * @param Model|Authenticatable|HasPermissions|null $user
     *
     * @return bool
     */
    protected function authorize($user): bool
    {
        return true;
    }
}
